package com.wzq.controller;

import java.util.List;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.wzq.bean.TownshipCollectionModel;
import com.wzq.service.TownshipCollectionService;
import com.wzq.util.ApiException;
import com.wzq.util.ApiResponse;
import com.wzq.util.Pager;
import com.wzq.util.ResponseCode;
import com.wzq.util.UploadPicUtil;

@Controller 
@RequestMapping("townshipcollection/")
public class TownshipCollectionController{
	@Autowired
	private TownshipCollectionService townshipCollectionService;


	@RequestMapping("dataList")
	@ResponseBody
	public ApiResponse<List<TownshipCollectionModel>> dataList(TownshipCollectionModel model,HttpServletRequest request,Pager pager)throws ApiException{
		ApiResponse<List<TownshipCollectionModel>> response = new  ApiResponse<List<TownshipCollectionModel>>(ResponseCode.SUCC);       
		List<TownshipCollectionModel> list = townshipCollectionService.queryList(model, pager);
		response.setData(list);	
		return response;
	}
	
	
	@RequestMapping("add")
	@ResponseBody
	public ApiResponse<String> add(TownshipCollectionModel model,HttpServletRequest request)throws ApiException{
		ApiResponse<String> response = new  ApiResponse<String>(ResponseCode.SUCC);
		townshipCollectionService.add(model);		
		UploadPicUtil.uploadPic(model.getPicFileStr(), model.getPic(), request.getRealPath("/")+"/picPath");
		return response;
	}
	
	@RequestMapping("update")
	@ResponseBody
	public ApiResponse<String> update(TownshipCollectionModel model,HttpServletRequest request)throws ApiException{
		ApiResponse<String> response = new  ApiResponse<String>(ResponseCode.SUCC);
		townshipCollectionService.updateBySelective(model);
		return response;
	}
	
	@RequestMapping("delete")
	@ResponseBody
	public ApiResponse<String> delete(Integer id,HttpServletRequest request)throws ApiException{
		ApiResponse<String> response = new  ApiResponse<String>(ResponseCode.SUCC);
		townshipCollectionService.delete(id);
		return response;
	}
	
	@RequestMapping("getById")
	@ResponseBody
	public ApiResponse<TownshipCollectionModel> getById(Integer id,HttpServletRequest request,Pager pager)throws ApiException{
		ApiResponse<TownshipCollectionModel> response = new  ApiResponse<TownshipCollectionModel>(ResponseCode.SUCC);       
		TownshipCollectionModel model = townshipCollectionService.getById(id);
		response.setData(model);	
		return response;
	}
	
	
}
